package com.nexgo.payment.trans.cardhint;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;

import com.nexgo.payment.R;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.ui.BaseActivity;
import com.nexgo.payment.widget.TitleBuilder;

/**
 * 拔卡提示界面
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月31日
 */
public class CardHintActivity extends BaseActivity implements CardHintContract.View {

    private CardHintContract.Presenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card_hint);

        getWindow().addFlags(3);  //屏蔽home键
        getWindow().addFlags(5);  //屏蔽菜单键

        initTitle();

        new CardHintPresenter(this, Repository.getInstance());
    }

    //初始化标题栏
    private void initTitle() {
        new TitleBuilder(this)
                .setExternalTitleBgRes(R.drawable.bg_blue_icon)
                .setTitleText(getString(R.string.no_pull_the_card))
                .build();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.start();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.destroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //拦截返回键，禁用返回按钮
            if (keyCode == KeyEvent.KEYCODE_BACK) return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void setPresenter(CardHintContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public void showSuccess() {
        finish();
    }

    public static Intent newInstance(Context context) {
        return new Intent(context, CardHintActivity.class);
    }
}
